<template>
  <div v-loading="loading" class="app-container home">
    <!-- <div>
      <div class="block">
        <span class="demonstration" style="margin-right:10px;">日期</span>
        <el-date-picker
          v-model="times"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
          value-format="yyyy-MM-dd"
        />
        <el-button type="success" @click="onSearch">查询</el-button>
      </div>
    </div>
    <div v-if="times.length" style="margin:20px 10px;font-size:30px;font-weight:bold;">
      {{ times[0] }} ~ {{ times[1] }}数据统计
    </div>
    <div style="margin:20px 0;">
      <el-row :gutter="20" style="text-align: center;">
        <el-col :sm="24" :lg="6" style="padding-left: 20px">
          <el-card class="update-log">
            <div class="data-title">
              微信用户新增数量
            </div>
            <div class="data-row">
              <div class="data-row-label" style="text-align:center;">{{ wxUser.num }}个</div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>
    <el-row :gutter="20" style="text-align: center">
      <el-col :sm="24" :lg="6" style="padding-left: 20px">
        <el-card class="update-log">
          <div class="data-title">
            结缘品
          </div>
          <div class="data-row">
            <div class="data-row-label">订单数</div>
            <div class="data-row-value">{{ order0.num || 0 }}</div>
          </div>
          <div class="data-row">
            <div class="data-row-label">金额</div>
            <div class="data-row-value">￥{{ order0.amount || 0 }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :sm="24" :lg="6" style="padding-left: 20px">
        <el-card class="update-log">
          <div class="data-title">
            道场建设
          </div>
          <div class="data-row">
            <div class="data-row-label">订单数</div>
            <div class="data-row-value">{{ order1.num || 0 }}</div>
          </div>
          <div class="data-row">
            <div class="data-row-label">金额</div>
            <div class="data-row-value">￥{{ order1.amount || 0 }}</div>
          </div>
        </el-card>
      </el-col>
      <el-col :sm="24" :lg="6" style="padding-left: 20px">
        <el-card class="update-log">
          <div class="data-title">
            供养牌位
          </div>
          <div class="data-row">
            <div class="data-row-label">订单数</div>
            <div class="data-row-value">{{ order2.num || 0 }}</div>
          </div>
          <div class="data-row">
            <div class="data-row-label">金额</div>
            <div class="data-row-value">￥{{ order2.amount || 0 }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row> -->
  </div>
</template>

<script>
import { dataIndex } from '@/api/mall/data'
import { parseTime } from '@/utils/ruoyi'
export default {
  name: 'Index',
  data() {
    return {
      // 版本号
      loading: false,
      order0: {},
      order1: {},
      order2: {},
      wxUser: {},
      times: [],
      pickerOptions: {
        shortcuts: [
          {
            text: '最近一周',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
              picker.$emit('pick', [start, end])
            }
          },
          {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date()
              const start = new Date()
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
              picker.$emit('pick', [start, end])
            }
          }
        ]
      }
    }
  },
  created() {
    const today = parseTime(new Date().getTime(), '{y}-{m}-{d}')
    this.times = [today, today]
    // this.onSearch()
  },
  methods: {
    onSearch() {
      this.loading = true
      dataIndex({
        beginTime: `${this.times[0]} 00:00:00`,
        endTime: `${this.times[1]} 23:59:59`
      }).then(res => {
        this.loading = false
        if (res.data.order && res.data.order.length) {
          res.data.order.map(x => {
            if (x.orderType == 0) {
              this.order0 = x
            }
            if (x.orderType == 1) {
              this.order1 = x
            }
            if (x.orderType == 2) {
              this.order2 = x
            }
          })
        }
        this.wxUser = res.data.wx
      }).catch(e => {
        this.loading = false
      })
    }
    // goTarget(href) {
    //   // window.open(href, '_blank')
    // }
  }
}
</script>

<style scoped lang="scss">
.home {
  blockquote {
    padding: 10px 20px;
    margin: 0 0 20px;
    font-size: 17.5px;
    border-left: 5px solid #eee;
  }
  hr {
    margin-top: 20px;
    margin-bottom: 20px;
    border: 0;
    border-top: 1px solid #eee;
  }
  .col-item {
    margin-bottom: 20px;
  }

  ul {
    padding: 0;
    margin: 0;
  }

  font-family: "open sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 13px;
  color: #676a6c;
  overflow-x: hidden;

  ul {
    list-style-type: none;
  }

  h4 {
    margin-top: 0px;
  }

  h2 {
    margin-top: 10px;
    font-size: 26px;
    font-weight: 100;
  }

  p {
    margin-top: 10px;

    b {
      font-weight: 700;
    }
  }

  .update-log {
    ol {
      display: block;
      list-style-type: decimal;
      margin-block-start: 1em;
      margin-block-end: 1em;
      margin-inline-start: 0;
      margin-inline-end: 0;
      padding-inline-start: 40px;
    }
  }
}

.data-title {
  font-weight: bold;
  color: #000;
  font-size: 20px;
  margin-bottom: 10px;
}
.data-row {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}
.data-row-label {
  font-size: 18px;
  flex: 1;
  text-align: left;
}
.data-row-value {
  text-align: center;
  font-size: 18px;
}
</style>
